package com.crl.ssc.dic.dao;

import com.cars.util.page.PageUtil;
import com.crl.dao.BaseDao;
import com.crl.ssc.dic.model.DicCz;
import com.crl.ssc.dic.vo.DicCzSearchVO;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @description: 字典管理-车站字典Dao
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020-07-26 23:24:46
 */
@Repository
public class DicCzDao extends BaseDao<DicCz, DicCzSearchVO> {
    /**
     * 新增
     *
     * @param dicCz
     * @return
     */
    public int add(DicCz dicCz) {
        String sql = "INSERT INTO td_dic_cz(CZDM,CZMC,LJDM,LJPYM) " +
                "VALUES(:czdm,:czmc,:ljdm,:ljpym)";
        return insert(sql, dicCz);
    }

    /**
     * 修改
     *
     * @param dicCz
     * @return
     */
    public int update(DicCz dicCz) {
        String sql = "UPDATE td_dic_cz SET CZMC=:czmc,LJDM=:ljdm,LJPYM=:ljpym " +
                    "WHERE CZDM=czdm";
        return update(sql, dicCz);
    }

    /**
     * 删除
     *
     * @param czdm
     * @return
     */
    public int delete(String czdm) {
        String sql = "DELETE FROM td_dic_cz WHERE CZDM=?";
        return delete(sql, czdm);
    }
    /**
     * 列表
     *
     * @param dicCzSearchVO
     * @return
     */
    public List<DicCz> list(DicCzSearchVO dicCzSearchVO) {
        String sql = "SELECT CZDM,CZMC,LJDM,LJPYM FROM td_dic_cz WHERE 1=1 ";
        sql += createSearchSQL(dicCzSearchVO);
        sql += " ORDER BY czdm ASC";
        sql = PageUtil.createOraclePageSQL(sql, dicCzSearchVO.getPage());
        return list(sql, dicCzSearchVO);
    }
    /**
     * 查询数据条数
     *
     * @param dicCzSearchVO
     * @return
     */
    public int count(DicCzSearchVO dicCzSearchVO) {
        String sql = "SELECT COUNT(CZDM) FROM td_dic_cz WHERE 1=1 ";
        sql += createSearchSQL(dicCzSearchVO);
        return count(sql, dicCzSearchVO);
    }
    /**
       * 拼接查询条件
       *
       * @param dicCzSearchVO
       * @return
    */
    private String createSearchSQL(DicCzSearchVO dicCzSearchVO) {
        String sql = "";
        
        return sql;
    }

    /**
     * 获取单个
     *
     * @param czdm
     * @return
     */
    public DicCz get(String czdm) {
        String sql = "SELECT CZDM,CZMC,LJDM,LJPYM FROM td_dic_cz WHERE CZDM=?";
        return get(sql, czdm);
    }
}
